package com.elitetyc.customview.activity;

import android.inputmethodservice.KeyboardView;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.InputType;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;

import com.blankj.utilcode.util.KeyboardUtils;
import com.elitetyc.customview.R;
import com.elitetyc.customview.utils.KeyBoardUtil;

import java.lang.reflect.Method;

public class AnQuanJianPanActivity extends AppCompatActivity {

    private EditText editText;
    private KeyboardView key_board_view;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_an_quan_jian_pan);
        key_board_view = findViewById(R.id.key_board_view);
        editText = findViewById(R.id.et_password);

        editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus){
//                    显示光标的情况下，不弹出输入框
                    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
                    try {
                        Class<EditText> cls = EditText.class;
                        Method setSoftInputShownOnFocus;
                        setSoftInputShownOnFocus = cls.getMethod("setShowSoftInputOnFocus", boolean.class);
                        setSoftInputShownOnFocus.setAccessible(true);
                        setSoftInputShownOnFocus.invoke(editText, false);
                        new KeyBoardUtil(key_board_view,editText).showKeyBoard();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }

            }
        });
    }
}
